/*
    Copyright 2021-2022. Huawei Technologies Co., Ltd. All rights reserved.

    Licensed under the Apache License, Version 2.0 (the "License")
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        https://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

part of huawei_gameservice;

/// Obtains the metadata of an archive, such as the description of an archive.
class ArchiveSummary {
  /// Whether the archive has a cover thumbnail.
  final bool? hasThumbnail;

  /// Unique file name of an archive, that is, the name of the locally saved file.
  ///
  /// The name is generated by Huawei game server.
  final String? fileName;

  /// ID of an archive, which is generated by Huawei game server.
  final String? id;

  /// Progress value of an archive.
  ///
  /// You need to define the value when submitting an archive.
  final int? currentProgress;

  /// New played time of an archive.
  ///
  /// You need to define the time when submitting an archive.
  final int? activeTime;

  /// A [Player] object that contains player information, excluding player information
  /// of [playerSign] and [signTs].
  final Player? gamePlayer;

  /// Timestamp when an archive was last modified.
  final int? recentUpdateTime;

  /// A [GameSummary] object that contains the basic game information associated with an archive.
  final GameSummary? gameSummary;

  /// The description of an archive.
  final String? descInfo;

  /// Cover image aspect ratio of an archive.
  final double? thumbnailRatio;

  const ArchiveSummary._({
    this.hasThumbnail,
    this.fileName,
    this.id,
    this.currentProgress,
    this.activeTime,
    this.gamePlayer,
    this.recentUpdateTime,
    this.gameSummary,
    this.descInfo,
    this.thumbnailRatio,
  });

  factory ArchiveSummary.fromMap(Map<dynamic, dynamic> map) {
    return ArchiveSummary._(
      hasThumbnail: map['hasThumbnail'],
      fileName: map['fileName'],
      id: map['id'],
      currentProgress: map['currentProgress'],
      activeTime: map['activeTime'],
      gamePlayer:
          map['gamePlayer'] != null ? Player.fromMap(map['gamePlayer']) : null,
      recentUpdateTime: map['recentUpdateTime'],
      gameSummary: map['gameSummary'] != null
          ? GameSummary.fromMap(map['gameSummary'])
          : null,
      descInfo: map['description'],
      thumbnailRatio: map['thumbnailRatio'],
    );
  }

  Map<String, dynamic> toMap() {
    return <String, dynamic>{
      'hasThumbnail': hasThumbnail,
      'fileName': fileName,
      'id': id,
      'currentProgress': currentProgress,
      'activeTime': activeTime,
      'gamePlayer': gamePlayer?.toMap(),
      'recentUpdateTime': recentUpdateTime,
      'gameSummary': gameSummary?.toMap(),
      'description': descInfo,
      'thumbnailRatio': thumbnailRatio,
    };
  }

  @override
  String toString() {
    return '$ArchiveSummary('
        'hasThumbnail: $hasThumbnail, '
        'fileName: $fileName, '
        'id: $id, '
        'currentProgress: $currentProgress, '
        'activeTime: $activeTime, '
        'gamePlayer: $gamePlayer, '
        'recentUpdateTime: $recentUpdateTime, '
        'gameSummary: $gameSummary, '
        'description: $descInfo, '
        'thumbnailRatio: $thumbnailRatio)';
  }
}
